package com.cyt.web.controller.phone;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.PhoneController;
import com.cyt.work.association.model.vo.WxAssociationSignVo;
import com.cyt.work.association.service.WxAssociationSignService;
import com.cyt.work.association.service.WxAssociationNewStuService;
import com.cyt.wx.model.po.WxEducationUser;
import com.cyt.wx.model.po.WxMember;
import com.cyt.wx.model.vo.WxEducationUserVo;
import com.cyt.wx.service.WxEducationUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 社团招新管理-社团报名管理控制层
 *
 * @author ding xu
 * @date 2019-9-17
 */
@RestController
public class PhoneAssociationSignController extends PhoneController {

    @Autowired
    private WxAssociationSignService wxAssociationSignService;
    @Autowired
    private WxEducationUserService wxEducationUserService;
    @Autowired
    private WxAssociationNewStuService wxAssociationNewStuService;


    /**
     * 社团报名
     *
     * @param request 请求对象
     * @param wxAssociationSignVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-9-17
     */
//    @BaseLog(module = "社团招新", classz = "社团报名", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/associationSign/wxassociationsign/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WxAssociationSignVo wxAssociationSignVo,String token){
        WxMember wxMember = acceptToken(token);
        WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
        wxEducationUserVo.setMemberId(wxMember.getId());
        List<WxEducationUser> wxEducationUserList = wxEducationUserService.listExample(wxEducationUserVo);
        //能登录进去就可以直接使用
        WxEducationUser wxEducationUser = wxEducationUserList.get(0);
        wxAssociationSignVo.setUserNumber(wxEducationUser.getUserNumber());
        return wxAssociationSignService.addOrUpdate(wxAssociationSignVo, wxMember,wxEducationUser);
    }


    /**
     * 社团退团
     *
     * @param request 请求对象
     * @param wxAssociationSignVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-9-17
     */
//    @BaseLog(module = "社团招新", classz = "社团退团", methods = "删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/associationSign/wxassociationsign/quitAssociation", method = RequestMethod.POST)
    public ReturnResult quitAssociation(HttpServletRequest request, WxAssociationSignVo wxAssociationSignVo,String token) {
        WxMember wxMember = acceptToken(token);
        WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
        wxEducationUserVo.setMemberId(wxMember.getId());
        List<WxEducationUser> wxEducationUserList = wxEducationUserService.listExample(wxEducationUserVo);
        //能登录进去就可以直接使用
        WxEducationUser wxEducationUser = wxEducationUserList.get(0);
        wxAssociationSignVo.setUserNumber(wxEducationUser.getUserNumber());
        return wxAssociationSignService.quitAssociation(wxAssociationSignVo, wxMember,wxEducationUser);
    }


    /**
     * 查询社团已报人数
     *
     * @param request 请求对象
     * @param wxAssociationSignVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-9-17
     */
//    @BaseLog(module = "社团招新", classz = "社团退团", methods = "查询社团已报人数", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/associationSign/wxassociationsign/hasAssSign", method = RequestMethod.POST)
    public ReturnResult hasAssSign(HttpServletRequest request, WxAssociationSignVo wxAssociationSignVo,String token,int page, int limit) {
        return wxAssociationNewStuService.findVoHasSignPage(wxAssociationSignVo,page,limit);
    }




}